package com.easyOrder.service.invoice;

import com.easyOrder.dao.ZZInvoiceExternalMapper;
import com.easyOrder.dto.OrderByMaterialDTO;
import com.easyOrder.dto.RequisitionDetailDTO;
import com.easyOrder.service.enums.RequisitionDetailState;
import com.easyOrder.service.enums.RequisitionState;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * Created by liutao on 2017/8/12.
 */
@Service
public class InvoiceService {

    @Autowired
    private ZZInvoiceExternalMapper invoiceExternalMapper;

    /**
     * 通过物料分组
     * @param branchId
     */
    public List<OrderByMaterialDTO> getDetailGroupByMaterial(Long branchId){
        HashMap<String,Object> map = Maps.newHashMap();
        map.put("branchId",branchId);
        map.put("status", RequisitionState.pay.getValue());
        map.put("statusDetail", RequisitionDetailState.pay.getValue());

        List<OrderByMaterialDTO> orderByMaterialDTOS = invoiceExternalMapper.selectOrderByMaterial(map);
        return orderByMaterialDTOS;
    }

    /**
     * 通过物料id查询明细
     * @param branchId
     * @param materialId
     * @return
     */
    public List<RequisitionDetailDTO> getDetailByMaterialId(Long branchId , Long materialId){
        HashMap<String,Object> map = Maps.newHashMap();
        map.put("branchId",branchId);
        map.put("materialId",materialId);
        List<Integer>  status = Lists.newArrayList();
        status.add(RequisitionState.pay.getValue());
        status.add(RequisitionState.receivingPart.getValue());
        map.put("status", status);
        map.put("statusDetail", RequisitionDetailState.pay.getValue());

        List<RequisitionDetailDTO> requisitionDetailDTOS = invoiceExternalMapper.selectDetailByMaterialId(map);
        return requisitionDetailDTOS;
    }


}
